local DIY = require "packages.diy_utility.diy_utility"

local skel = fk.CreateSkill({
    name = "sj3__jijun",
    tags = {DIY.ReadySkill},
  })
  
  Fk:loadTranslationTable{
    ["sj3__jijun"] = "集军",
    [":sj3__jijun"] = "<b><a href='diy_ready_skill'>蓄势技</a></b>，摸牌阶段，你可改为摸体力值张牌，然后将六面骰子翻至正对面。 ",
  
    ["#sj3__jijun"] = "集军：你可以改为摸 %arg 张牌，然后将体力值调整为 %arg2",
  
    ["$sj3__jijun1"] = "集民力万千，亦可为军。 ",
    ["$sj3__jijun2"] = "集万千义军，定天下大局。",
  }

  skel:addEffect(fk.DrawNCards, {
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(skel.name) and target == player
    end,
    on_cost = function (self, event, target, player, data)
      local hp = player.hp
      local box = {}
      for i = 6, 1, -1 do
        table.insert(box,i)
      end
      if player.room:askToSkillInvoke(player,{
        skill_name = skel.name,
        prompt = "#sj3__jijun:::"..hp..":"..box[hp]
      }) then
        event:setCostData(self,{hp = box[hp]})
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
      data.n = player.hp
      data.extra_data = data.extra_data or {}
      data.extra_data.sj3__jijun = event:getCostData(self).hp
    end,
  })

  skel:addEffect(fk.AfterDrawNCards, {
  mute = true,
  is_delay_effect = true,
  can_refresh = function(self, event, target, player, data) --没骰子不让调整
    return target == player and player:hasSkill("sj3__liufang",true) and data.extra_data and data.extra_data.sj3__jijun
  end,
  on_refresh = function(self, event, target, player, data)
    local hp = data.extra_data.sj3__jijun
    if player.hp ~= hp and not player.dead then
      if hp > player.hp then
        Room:recover{
          who = player,
          num = hp - player.hp,
          skillName = skel.name,
          recoverBy = player,
        }
      else
        Room:loseHp(player,player.hp - hp, skel.name)
      end
    end
  end,
})

return skel